﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true"
    CodeFile="MyUsers.aspx.cs" Inherits="MyUsers" %>

<asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" runat="Server">
    <asp:Panel ID="AuthenticatedHeaderPanel" runat="server">
        <ul id="user">
            <li>
                <asp:LoginStatus ID="LoginStatus1" runat="server" LogoutAction="Redirect" LogoutPageUrl="~/Login.aspx" />
            </li>
        </ul>
        <div id="header-inner">
            <div class="textt">
                <h4>
                    <asp:Label runat="server" ID="WelcomeBackMessage"></asp:Label>
                    <asp:Label ID="lblMessage" runat="server" EnableViewState="false" />
                </h4>
            </div>
        </div>
    </asp:Panel>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="Menu" runat="Server">
    <div id="left">
        <div id="navigation">
            <asp:panel runat="server" id="AuthenticatedMenuPanel" width="200px">
                <div id="menu-header">
                    <div class="menutext">
                        <asp:label ID="Label1" runat="server" text="Menu" />
                    </div>
                </div>
                <asp:menu id="Menu1" runat="server" staticdisplaylevels="3" backcolor="White" dynamichoverstyle-borderstyle="NotSet" width="200px">
                   <items>                
                    <asp:MenuItem Text="Home" Value="Home" navigateurl="Default.aspx">
                      <%--<asp:MenuItem Text="New Document" Value="New Document" navigateurl="AddDocument.aspx"/>--%>
                    </asp:MenuItem>

                    <asp:MenuItem Text="Users" Value="My_Users" navigateurl="MyUsers.aspx">
                      <%--<asp:MenuItem Text="New User" Value="New_User" navigateurl="AddUser.aspx">--%>
                    </asp:MenuItem>

                    <asp:MenuItem Text="Companies" Value="Companies" navigateurl="MyCompanies.aspx">
                      <%--<asp:MenuItem Text="New Company" Value="New_Company" navigateurl="AddCompany.aspx"/>--%>
                    </asp:MenuItem>

                    <asp:MenuItem Text="Clients" Value="Clients" navigateurl="MyClients.aspx">
                      <%--<asp:MenuItem Text="New Client" Value="New_Client" navigateurl="AddClient.aspx"/>--%>                   
                    </asp:MenuItem>
                  </items>
                </asp:menu>
            </asp:panel>
        </div>
    </div>
</asp:Content>
<asp:Content ID="Content3" runat="server" ContentPlaceHolderID="MainContent">
    <div id="right">
        <asp:Panel runat="server" ID="AuthenticatedMessagePanel">
          <asp:ScriptManager ID="ScriptManager1" runat="server"/>
            <div class="box">
                <div class="title">
                    <h6>
                        <asp:Label ID="Label3" runat="server" Text="My profile"></asp:Label>
                    </h6>
                </div>
                <div class="lists">
                    <asp:ListView ID="user_list" runat="server" OnItemCommand="user_list_ItemCommand" OnItemDataBound="user_list_ItemDataBound" OnItemEditing="user_list_ItemEditing">
                        <LayoutTemplate>
                            <table id="gradient-style" class="tab">
                                <thead>
                                    <tr>
                                        <th>Name</th>
                                        <th>Secondname</th>
                                        <th>Login</th>
                                        <th>Email</th>
                                        <th>Licence</th>
                                        <th>Superuser</th>
                                        <th>Activated</th>
                                        <th>Additional user</th>
                                        <th colspan="2">Options</th>
                                    </tr>
                                </thead>
                                <tr id="itemPlaceholder" runat="server">
                                </tr>
                                <tfoot>
                                    <tr>
                                        <th style="text-align: right" colspan="11">
                                        </th>
                                    </tr>
                                </tfoot>
                            </table>
                        </LayoutTemplate>
                        <ItemTemplate>
                            <tr>
                                <td id="idL" runat="server">
                                    <asp:Label ID="my_idLabel" runat="server" Text='<%# Eval("_id") %>' />
                                </td>
                                <td>
                                    <asp:Label ID="my_nameLabel" runat="server" Text='<%# Eval("_name") %>' />
                                </td>
                                <td>
                                    <asp:Label ID="my_secondnameLabel" runat="server" Text='<%# Eval("_secondname") %>' />
                                </td>
                                <td>
                                    <asp:Label ID="my_loginLabel" runat="server" Text='<%# Eval("_login") %>' />
                                </td>
                                <td>
                                    <asp:Label ID="my_emailLabel" runat="server" Text='<%# Eval("_email") %>' />
                                </td>
                                <td>
                                    <asp:Label ID="my_id_licenceLabel" runat="server" Text='<%# Eval("_licence") %>' />
                                </td>
                                <td>
                                    <asp:CheckBox ID="my_superuserCheckBox" runat="server" Checked='<%# Eval("_superuser") %>' Enabled="false" />
                                </td>
                                <td>
                                    <asp:CheckBox ID="my_activatedCheckBox" runat="server" Checked='<%# Eval("_activated") %>' Enabled="false" />
                                </td>
                                <td>
                                    <asp:CheckBox ID="my_additional_userCheckBox" runat="server" Checked='<%# Eval("_additional_user") %>' Enabled="false" />
                                </td>
                                <td>
                                    <asp:ImageButton ID="my_lnkEdit" runat="server" CommandName="Edit" ImageUrl="~/Images/user_edit.png" ToolTip="Edit" Width="20" Height="20"/>
                                </td>
                            </tr>
                        </ItemTemplate>
                    </asp:ListView>
                </div>
            </div>
            <div class="box">
                <div class="title">
                    <h6>
                        <asp:Label ID="Label2" runat="server" Text="My users"></asp:Label>
                    </h6>
                </div>
                <div class="lists">
<%--                   <asp:UpdatePanel ID="UpdateMyUserList" runat="server" UpdateMode="Conditional">
                   <ContentTemplate>--%>
                    <asp:ListView ID="My_user_list" runat="server" OnItemCommand="My_user_list_ItemCommand" OnItemDataBound="My_user_list_ItemDataBound" OnItemEditing="My_user_list_ItemEditing" OnItemDeleting="My_user_list_ItemDeleting" OnPagePropertiesChanging="My_user_list_PagePropertiesChanging">
                        <LayoutTemplate>
                            <table id="gradient-style" class="tab">
                                <thead>
                                    <tr>
                                        <th>Name</th>
                                        <th>Secondname</th>
                                        <th>Login</th>
                                        <th>Email</th>
                                        <th>Licence</th>
                                        <th>Superuser</th>
                                        <th>Activated</th>
                                        <th>Additional user</th>
                                        <th>Statuss</th>
                                        <th colspan="2">Options</th>
                                    </tr>
                                </thead>
                                <tr id="itemPlaceholder" runat="server">
                                </tr>
                                <tfoot>
                                    <tr>
                                        <th style="text-align: right" colspan="12">
                                            <asp:DataPager ID="My_users_list_Page" runat="server" PagedControlID="My_user_list" PageSize="5">
                                                <Fields>
                                                    <asp:NextPreviousPagerField ButtonType="Button" ShowFirstPageButton="True" ShowNextPageButton="False" ShowPreviousPageButton="False" />
                                                    <asp:NumericPagerField />
                                                    <asp:TemplatePagerField>
                                                        <PagerTemplate>
                                                            Page
                                                            <asp:Label runat="server" ID="labelCurrentPage" Text="  <%  #  Container.TotalRowCount > 0 ? (Container.StartRowIndex / Container.PageSize) + 1 : 0  %>  " />
                                                            /
                                                            <asp:Label runat="server" ID="labelTotalPages" Text="  <%  #   Math.Ceiling ((double)Container.TotalRowCount / Container.PageSize)  %>  " />
                                                        </PagerTemplate>
                                                    </asp:TemplatePagerField>
                                                    <asp:NextPreviousPagerField ButtonType="Button" ShowLastPageButton="True" ShowNextPageButton="False" ShowPreviousPageButton="False" />
                                                </Fields>
                                            </asp:DataPager>
                                        </th>
                                    </tr>
                                </tfoot>
                            </table>
                        </LayoutTemplate>
                        <ItemTemplate>
                            <tr>
                                <td id="idL" runat="server">
                                    <asp:Label ID="idLabel" runat="server" Text='<%# Eval("_id") %>' />
                                </td>
                                <td>
                                    <asp:Label ID="nameLabel" runat="server" Text='<%# Eval("_name") %>' />
                                </td>
                                <td>
                                    <asp:Label ID="secondnameLabel" runat="server" Text='<%# Eval("_secondname") %>' />
                                </td>
                                <td>
                                    <asp:Label ID="loginLabel" runat="server" Text='<%# Eval("_login") %>' />
                                </td>
                                <td>
                                    <asp:Label ID="emailLabel" runat="server" Text='<%# Eval("_email") %>' />
                                </td>
                                <td>
                                    <asp:Label ID="ID_licenceLabel" runat="server" Text='<%# Eval("_licence") %>' />
                                </td>
                                <td>
                                    <asp:CheckBox ID="superuserCheckBox" runat="server" Checked='<%# Eval("_superuser") %>' Enabled="false" />
                                </td>
                                <td>
                                    <asp:CheckBox ID="activatedCheckBox" runat="server" Checked='<%# Eval("_activated") %>' Enabled="false" />
                                </td>
                                <td>
                                    <asp:CheckBox ID="additional_userCheckBox" runat="server" Checked='<%# Eval("_additional_user") %>' Enabled="false" />
                                </td>
                                <td>
                                    <asp:Label ID="statussLabel" runat="server" Text='<%# Eval("_statuss") %>' />
                                </td>
                                <td>
                                    <asp:ImageButton ID="lnkEdit" runat="server" CommandName="Edit" ImageUrl="~/Images/user_edit.png" ToolTip="Edit" Width="20" Height="20"/>
                                </td>
                                <td>
                                    <asp:ImageButton ID="lnkDelete" runat="server" CommandName="Delete" ImageUrl="~/Images/user_delete.png" ToolTip="Delete" Width="20" Height="20"/>
                                </td>
                            </tr>
                        </ItemTemplate>
                    </asp:ListView>
                    <div class="message-notice" id="message" runat="server">
                        <div class="image">
                            <img height="32" alt="Notice" src="Images/notice.png">
                        </div>
                        <div class="text">
                            <h4>You have no users!</h4>
                        </div>
                    </div>
<%--                   </ContentTemplate>
                   </asp:UpdatePanel>--%>
                    <div style="padding-top:15px;">
                        <asp:Button ID="bt_add_user" runat="server" Text="Add new user" OnClick="bt_add_user_Click" CssClass="GreenBtn" />
                    </div>
                </div>
              </div>
                <%--New user POPUP--%>
                    <asp:Panel ID="PopupNewUser" runat="server" CssClass="popupBody" Style="display: none">
                      <asp:UpdatePanel ID="Update_panel" runat="server" UpdateMode="Conditional">
                       <ContentTemplate>
                        <div class="popupContainer" style="width: auto; min-width: 350px; height:auto;">
                            <div class="popupTitlebar">
                                <div class="titlebarLeft">
                                    <asp:Literal ID="lit_add_user" runat="server" Text="Add new user!" />
                                </div>
                                <div class="titlebarRight" onclick="OnCancel();">
                                </div>
                            </div>
                            <div class="popupBody" id="login" runat="server">

                                <asp:Label ID="lblMainUser" runat="server" />
                                <asp:Label ID="lbluser_id" runat="server" />
                                <asp:Label ID="lblMainUser_id" runat="server" />
                                <asp:Label ID="lblUserEdit" runat="server" />
                                <table style="border-bottom: 1px solid #CDCDCD; color: #292929; font-family: Arial,Helvetica,sans-serif; font-size: 0.9em; line-height: 1.4em; padding: 5px 7px; width:100%; text-align:left;">
                                    <tbody>
                                        <tr>
                                            <th style="text-align:left;">Name:</th>
                                        </tr>
                                        <tr>                                            
                                            <td style="border-right: none; text-align: left; padding: 3px 1px 4px 0;">
                                                <asp:TextBox ID="tb_name" runat="server" ValidationGroup="edit" CssClass="glowTextbox"/>
                                                <asp:RequiredFieldValidator ID="NameValidator" runat="server" ControlToValidate="tb_name" SetFocusOnError="true" Display="Dynamic"
                                                    ValidationGroup="add" ><asp:Image ID="Image1" runat="server" ImageUrl="~/Images/Warning.png" ToolTip="Name cannot be blank!" ImageAlign="AbsMiddle"></asp:Image></asp:RequiredFieldValidator>
                                            </td>
                                        </tr>
                                        <tr>
                                            <th style="text-align:left;">Secondname:</th>
                                        </tr>
                                        <tr>
                                            <td style="border-right: none; text-align: left; padding: 3px 1px 4px 0;">
                                                <asp:TextBox ID="tb_secondname" runat="server" ValidationGroup="edit" CssClass="glowTextbox"/>
                                                <asp:RequiredFieldValidator ID="SecondnameValidator" runat="server" ControlToValidate="tb_secondname" SetFocusOnError="true" Display="Dynamic" 
                                                    ValidationGroup="add"><asp:Image ID="Image2" runat="server" ImageUrl="~/Images/Warning.png" ToolTip="Secondname cannot be blank!" ImageAlign="AbsMiddle"></asp:Image></asp:RequiredFieldValidator>
                                            </td>
                                        </tr>
                                        <tr>
                                            <th style="text-align:left;">Login:</th>
                                        </tr>
                                        <tr>                                            
                                            <td style="border-right: none; text-align: left; padding: 3px 1px 4px 0;">
                                                <asp:TextBox ID="tb_login" runat="server" ValidationGroup="edit" CssClass="glowTextbox"/>
                                                <asp:RequiredFieldValidator ID="LoginValidator" runat="server" ControlToValidate="tb_login" SetFocusOnError="true" Display="Dynamic"
                                                    ValidationGroup="add"><asp:Image ID="Image3" runat="server" ImageUrl="~/Images/Warning.png" ToolTip="Login cannot be blank!" ImageAlign="AbsMiddle"></asp:Image></asp:RequiredFieldValidator>
                                            </td>
                                        </tr>
                                        <tr>
                                            <th style="text-align:left;">Password:</th>
                                        </tr>
                                        <tr>                                            
                                            <td style="border-right: none; text-align: left; padding: 3px 1px 4px 0;">
                                                <asp:TextBox ID="tb_password" runat="server" ValidationGroup="edit" CssClass="glowTextbox"/>
                                                <asp:RequiredFieldValidator ID="PaswordValidator" runat="server" ControlToValidate="tb_password" SetFocusOnError="true" Display="Dynamic"
                                                    ValidationGroup="add"><asp:Image ID="Image4" runat="server" ImageUrl="~/Images/Warning.png" ToolTip="Password cannot be blank!" ImageAlign="AbsMiddle"></asp:Image></asp:RequiredFieldValidator>
                                            </td>
                                        </tr>
                                        <tr>
                                            <th style="text-align:left;">E-mail:</th>
                                        </tr>
                                        <tr>
                                            <td style="border-right: none; text-align: left; padding: 3px 1px 4px 0;">
                                                <asp:TextBox ID="tb_email" runat="server" ValidationGroup="add" CssClass="glowTextbox"/>

                                                <asp:RegularExpressionValidator ID="revtxtEmail" ControlToValidate="tb_email" ValidationGroup="add" Display="Dynamic" 
                                                    ValidationExpression="^([0-9a-zA-Z]([-.\w]*[0-9a-zA-Z])*@([0-9a-zA-Z][-\w]*[0-9a-zA-Z]\.)+[a-zA-Z]{2,9})$" runat="server" EnableClientScript="false">
                                                    <asp:Image ID="Image6" runat="server" ImageUrl="~/Images/Warning.png" ToolTip="Invalid E-mail!" ImageAlign="AbsMiddle"></asp:Image></asp:RegularExpressionValidator>

                                                <asp:RequiredFieldValidator ID="EmailValidator" runat="server" ControlToValidate="tb_email" SetFocusOnError="true" Display="Dynamic" validationGroup="add">
                                                    <asp:Image ID="Image5" runat="server" ImageUrl="~/Images/Warning.png" ToolTip="E-mail cannot be blank!" ImageAlign="AbsMiddle"></asp:Image></asp:RequiredFieldValidator>
                                            </td>
                                        </tr>
                                        <tr>
                                            <th style="text-align:left;">Licence:</th>
                                        </tr>
                                        <tr>
                                            <td style="border-right: none; text-align: left; padding: 3px 1px 4px 0;">
                                                <asp:DropDownList ID="DropLicence" runat="server" CssClass="glowTextbox" Height="28px" />
                                                <asp:RequiredFieldValidator ID="LicenceValidator" runat="server" ControlToValidate="DropLicence" SetFocusOnError="true" Display="Dynamic" ValidationGroup="add" InitialValue="--Select--">
                                                <asp:Image ID="Image7" runat="server" ImageUrl="~/Images/Warning.png" ToolTip="Licence cannot be blank!" ImageAlign="AbsMiddle"></asp:Image></asp:RequiredFieldValidator>
                                            </td>
                                        </tr>
                                        <tr>
                                            <th style="text-align:left;">Role:</th>
                                        </tr>
                                        <tr>
                                            <th style="text-align:left;"><asp:CheckBox ID="check_superuser" runat="server" Text=" " />Superuser</th>
                                        </tr>
                                        <tr>
                                            <th style="text-align:left;"><asp:CheckBox ID="check_activated" runat="server" Text=" " />Activated</th>
                                        </tr>
                                        <tr>
                                            <th style="text-align:left;"><asp:CheckBox ID="check_additional_user" runat="server" Text=" "/>Additional user</th>
                                        </tr>
                                    </tbody>
                                </table>
                            </div>
                            <div style="text-align:center; padding:10px;">
                                <asp:Label ID="modal_message_user" runat="server" Text="&nbsp" style="font-size:0.9em; font-weight:bold;"/>
                            </div>
                            <div class="buttons">
                                <asp:button CssClass="BlueBtn" id="bt_adduser" runat="server" onclick="bt_adduser_Click" causesvalidation="true" validationgroup="add" Text="Save"></asp:button>
                                <asp:button CssClass="CancelBtn" id="bt_Cancel" runat="server" onclick="bt_adduser_cancel_Click" causesvalidation="false" Text="Cancel"></asp:button>
                            </div>
                            
                        </div>
                       </div>
                       
                       </ContentTemplate>
                       <Triggers>
                            <asp:AsyncPostBackTrigger ControlID="bt_adduser" EventName="click" />
                       </Triggers>
                       </asp:UpdatePanel>
                    </asp:Panel>
                    <asp:HiddenField ID="HiddenField1" runat="server" />
                    <ajaxToolkit:ModalPopupExtender ID="Modal_Popup_New_User" runat="server" TargetControlID="HiddenField1" PopupControlID="PopupNewUser" CancelControlID="bt_Cancel" BackgroundCssClass="modalPopupBackground" />
               <%--Delete User Popup --%>
                <asp:Panel ID="PopupDelete" runat="server" CssClass="popupBody" style="display: none">
                    <div class="popupContainer" style="width: auto; min-width: 400px">
                        <div class="popupTitlebar">
                            <div class="titlebarLeft">
                                <asp:Literal ID="Literal1" runat="server" Text="Delete!" />
                            </div>
                            <div class="titlebarRight" onclick="OnCancel();"></div>
                        </div>
                        <div class="popupBody">
                            <div id="content" style="background: none; min-height: 0px;">
                                <asp:Label ID="lbl_userID" runat="server" />
                                <div class="box" style="min-height: 0px;">
                                    <div class="message-notice" id="message4" runat="server">
                                        <div class="image">
                                            <img height="32" alt="Notice" src="Images/notice.png">
                                        </div>
                                        <div class="text">
                                            <h4>Are you sure?</h4>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                        <div class="buttons">
                            <button class="BlueBtn" id="bt_delete_user" runat="server" onserverclick="bt_delete_user_Click" style="width: auto;"><span class="label">Delete</span></button>
                            <button class="CancelBtn" id="bt_Cancel_delete" runat="server" onserverclick="bt_delete_cancel_Click" style="width: auto;"><span class="label">Cancel</span></button>
                        </div>
                    </div>
                </asp:Panel>
                <asp:hiddenfield id="HiddenField7" runat="server" />
                <ajaxToolkit:ModalPopupExtender ID="Modal_Popup_Delete" runat="server" TargetControlID="HiddenField7" PopupControlID="PopupDelete" CancelControlID="bt_Cancel_delete" BackgroundCssClass="modalPopupBackground" />                

          </asp:Panel>
    </div>
    <script type="text/javascript">
        function OnCancel() {
            document.getElementById('<%=bt_Cancel.ClientID%>').click();
        };
    </script>
</asp:Content>
